home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / DTS QT Utilities.May-95 / Projects & Test Apps / DigitizerShell / Mac Framework / MacApplication.c < prev    next >
Encoding:
Text File  |  1995-04-30  |  7.1 KB  |  313 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        MacApplication.c
  3.  
  4.     Contains:    Digitizer Shell specific functions concerning the application shell.
  5.  
  6.     Written by:    DTS
  7.  
  8.     Copyright:    © 1994-1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.        <1>         4/25/95        khs        first file
  13.        
  14. */
  15.  
  16.  
  17. // INCLUDES
  18. #include "MacApplication.h"
  19. #include "MacFramework.h"
  20. #include "AppConfiguration.h"
  21. #include "DTSQTUtilities.h"
  22.  
  23. // Header file for the specific test functions.
  24. #include "TestFunctions.h"
  25.  
  26. // GLOBALS
  27. long gMaxMilliSecToUse = 0L;        
  28.  
  29. // These are our global SG settings, if needed we need to export these using get/set functions
  30. // as these are internal to this file (.c).
  31. SeqGrabComponent     gSG = NULL;
  32. WindowPtr                gCaptureWindow = NULL;
  33. SGChannel                    gVideoChannel = NULL;
  34. SGChannel                    gAudioChannel = NULL;
  35.  
  36.  
  37.  
  38. // FUNCTIONS
  39. // ______________________________________________________________________
  40. void DoIdle(WindowRef theWindow)
  41. {
  42.     GrafPtr                 aSavedPort;
  43.     
  44.     GetPort(&aSavedPort);
  45.     SetPort(theWindow);
  46.     
  47.     // Update the SG port assuming it's in use.
  48.     if(gSG != NULL)
  49.          SGIdle(gSG);
  50.     
  51. // @@@INSERT ANY IDLE BASED FUNCTIONALITY HERE
  52.  
  53.     SetPort(aSavedPort);
  54. }
  55.  
  56.  
  57. // ______________________________________________________________________
  58. void DoUpdateWindow(WindowRef theWindow, Rect *theRefrehArea)
  59. {
  60.     GrafPtr aSavedPort;
  61.     
  62.     GetPort(&aSavedPort);
  63.     SetPort(theWindow);
  64.     
  65.     BeginUpdate(theWindow);
  66.  
  67.     if(gSG != NULL)
  68.         SGUpdate(gSG, NULL);
  69.         
  70. // @@@INSERT WINDOW SPECIFIC DRAWING FUNCTIONALITY HERE
  71.  
  72.     EndUpdate(theWindow);
  73.     SetPort(aSavedPort);
  74. }
  75.  
  76.  
  77.  
  78. // ______________________________________________________________________
  79. void DoCloseWindow(WindowRef theWindow)
  80. {
  81.     OSErr anErr = noErr;
  82.  
  83.     gCaptureWindow = NULL;
  84.     
  85.     // Clean up the channels (CloseComponent will handle that).
  86.     anErr = CloseComponent(gSG);  DebugAssert(anErr != noErr);
  87.     gSG = NULL; gVideoChannel = NULL; gAudioChannel = NULL;
  88. }
  89.  
  90.  
  91. // ______________________________________________________________________
  92. void     DoDragWindow(WindowRef theWindow, EventRecord *theEvent)
  93. {
  94.     GrafPtr aSavedPort;
  95.     ICMAlignmentProcRecord alignProc;
  96.     
  97.     GetPort(&aSavedPort);
  98.     SetPort(theWindow);
  99.     
  100.     if(gSG != NULL)
  101.     {
  102.         SGPause(gSG, TRUE);
  103.         SGGetAlignmentProc(gSG, &alignProc);
  104.         
  105.         DragAlignedWindow(theWindow, theEvent->where, &qd.screenBits.bounds, NULL, &alignProc);
  106.         SGPause(gSG, FALSE);
  107.     }
  108.     // @@@INSERT WINDOW DRAGGING SPECIFIC FUNCTIONALITY HERE
  109.         
  110.     SetPort(aSavedPort);
  111. }
  112.  
  113. // ______________________________________________________________________
  114. void HandleContentClick(WindowRef theWindow, EventRecord *theEvent)
  115. {
  116.     GrafPtr aSavedPort;
  117.     
  118.     GetPort(&aSavedPort);
  119.     SetPort(theWindow);
  120.  
  121.     // @@@INSERT APPLICATION SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
  122.  
  123.     SetPort(aSavedPort);
  124. }
  125.  
  126.  
  127.  
  128. // ______________________________________________________________________
  129. WindowRef CreateMovieWindow(Rect *theRect, Str255 theTitle)
  130. {
  131.     WindowPtr    aWindow = NULL;
  132.     Rect                devRect;
  133.     
  134.         GetBestDeviceRect(NULL, &devRect);
  135.         
  136.         OffsetRect(theRect, devRect.left + 20, devRect.top + 20);
  137.         aWindow = NewCWindow( NULL, theRect, theTitle, TRUE, noGrowDocProc, (WindowPtr)-1,
  138.                                                 TRUE, 0);
  139.     return aWindow;
  140. }
  141.  
  142. // ______________________________________________________________________
  143. void HandleApplicationMenu(short theMenuID, short theMenuItem)
  144. {
  145.     //  HANDLE ANY ADDITIONAL MENU ENTRIES HERE
  146.     switch(theMenuID)
  147.     {
  148.         // Test menus.
  149.         case mTesting:
  150.             switch(theMenuItem)
  151.             {
  152.                 case iTest1:
  153.                 {
  154.                     ShowVDIGInfo();
  155.                     break;
  156.                 }
  157.                 
  158.                 case iTest2:
  159.                 {
  160.                     SetMyVideoChannelSettings();
  161.                     break;
  162.                 }
  163.                 
  164.                 case iTest3:
  165.                 {
  166.                     SetMyAudioChannelSettings();
  167.                     break;
  168.                 }
  169.             }
  170.             break;
  171.         
  172.         // Capture Size Menus.
  173.         case mCaptureSize:
  174.         {
  175.             switch(theMenuItem)
  176.             {
  177.                 case iSizeNormal:
  178.                 {
  179.                     if( QTUChangeSGWindowSize( GetDefaultSGInstance(), GetDefaultVideoChannel() , gCaptureWindow, 320L, 240L) != noErr)
  180.                         SysBeep(kDefaultSysBeep);
  181.                     break;
  182.                 }
  183.                 
  184.                 case iSizeSmall:
  185.                 {
  186.                     if ( QTUChangeSGWindowSize( GetDefaultSGInstance(), GetDefaultVideoChannel() , gCaptureWindow,160L, 120L) != noErr)
  187.                             SysBeep(kDefaultSysBeep);
  188.                     break;
  189.                 }
  190.                 
  191.                 case iSizeBig:
  192.                 {
  193.                     if ( QTUChangeSGWindowSize( GetDefaultSGInstance(), GetDefaultVideoChannel() , gCaptureWindow, 640L, 480L) != noErr)
  194.                         SysBeep(kDefaultSysBeep);
  195.                     break;
  196.                 }
  197.             }
  198.         break;
  199.         }
  200.         
  201.         // End testing menus
  202.     }
  203. }
  204.  
  205.  
  206. // ______________________________________________________________________
  207. void    AdjustApplicationMenus(void)
  208. {
  209.  
  210.     // For the time being always dim the edit entries (maybe later if needed enable these)
  211.     DisableItem(GetMHandle(mEdit), iUndo);
  212.     DisableItem(GetMHandle(mEdit), iCut);
  213.     DisableItem(GetMHandle(mEdit), iCopy);
  214.     DisableItem(GetMHandle(mEdit), iPaste);
  215.     DisableItem(GetMHandle(mEdit), iClear);
  216.     DisableItem(GetMHandle(mEdit), iSelectAll);
  217.     
  218.     // Test if we have a valid capture window open, if true, then enable the right menus, otherwise
  219.     // disable them.
  220.     if(gCaptureWindow != NULL)
  221.     {
  222.         DisableItem(GetMHandle(mFile), iNew);
  223.         EnableItem(GetMHandle(mFile), iClose);
  224.     
  225.         EnableItem(GetMHandle(mTesting), iTest1);
  226.  
  227.         EnableItem(GetMHandle(mTesting), iTest2);
  228.         EnableItem(GetMHandle(mTesting), iTest3);
  229.  
  230.         EnableItem(GetMHandle(mCaptureSize), iSizeNormal);
  231.         EnableItem(GetMHandle(mCaptureSize), iSizeSmall);
  232.         EnableItem(GetMHandle(mCaptureSize), iSizeBig);
  233.     }
  234.     else
  235.     {
  236.         EnableItem(GetMHandle(mFile), iNew);
  237.         DisableItem(GetMHandle(mFile), iClose);
  238.  
  239.         DisableItem(GetMHandle(mTesting), iTest1);
  240.         DisableItem(GetMHandle(mTesting), iTest2);
  241.         DisableItem(GetMHandle(mTesting), iTest3);
  242.  
  243.         DisableItem(GetMHandle(mCaptureSize), iSizeNormal);
  244.         DisableItem(GetMHandle(mCaptureSize), iSizeSmall);
  245.         DisableItem(GetMHandle(mCaptureSize), iSizeBig);
  246.     }
  247. }
  248.  
  249.  
  250. // ______________________________________________________________________
  251. void CreateSGEnviroment(void)
  252. {
  253.     OSErr                        anErr = noErr;
  254.     WindowPtr                 aWin = NULL;
  255.     Rect                            defRect = {20, 20, 260, 340};
  256.     
  257.     if(gSG != NULL || gCaptureWindow != NULL)    // already in use
  258.         return;
  259.     
  260.     gCaptureWindow = CreateMovieWindow(&defRect, "\pSG Grabber Window");
  261.     DebugAssert(gCaptureWindow != NULL);
  262.     
  263.     gSG = QTUCreateSequenceGrabber(gCaptureWindow); DebugAssert(sg != NULL);
  264.     if(gSG == NULL) 
  265.     {
  266.         printf("ERROR: Problem opening the default Sequence Grabber component.\n");
  267.         goto Closure;
  268.     }
  269.     
  270.     anErr = QTUCreateSGGrabChannels(gSG, &gCaptureWindow->portRect, seqGrabPlayDuringRecord + seqGrabRecord,
  271.                          &gVideoChannel, &gAudioChannel); DebugAssert(anErr == noErr); DebugAssert(anErr != noErr);
  272.     if(anErr != noErr) 
  273.     {
  274.         printf("ERROR: Problems creating the Video and Audio SG Channels: %ld.\n", anErr);    
  275.         goto Closure;
  276.     }            
  277.  
  278.     anErr = SGStartPreview(gSG); DebugAssert(anErr == noErr);
  279.     if(anErr != noErr) 
  280.     {
  281.         printf("ERROR: Problems starting the SG Preview: %ld.\n", anErr);
  282.         goto Closure;
  283.     }
  284.     else
  285.         printf("STATUS: Opened Default SG component, created channels (audio, sound), started Preview.\n");
  286.  
  287. Closure:
  288.     return;
  289. }
  290.  
  291.  
  292.  
  293. // ______________________________________________________________________
  294. SeqGrabComponent    GetDefaultSGInstance(void)
  295. {
  296.     return gSG;
  297. }
  298.  
  299.  
  300. SGChannel GetDefaultVideoChannel(void)
  301. {
  302.     return gVideoChannel;
  303. }
  304.  
  305.  
  306. SGChannel GetDefaultAudioChannel(void)
  307. {
  308.     return gAudioChannel;
  309. }
  310.  
  311.  
  312.  
  313.